<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>指令</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <!-- 自定义指令 -->
    <div id="app1">
        <p v-upper-text="msg1"></p>
        <p v-lower-text="msg1"></p>
    </div>
    <div id="app2">
        <p v-upper-text="msg2"></p>
        <!-- <p v-lower-text="msg2"></p> -->
    </div>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
    <script>
        //定义全局指令
        //el:指定属性所在的标签对象
        //binding：包含指令相关信息数据的对象
        Vue.directive('upper-text', function (el, binding) {
            console.log(el, binding);
            el.textContent = binding.value.toUpperCase();
        })
        new Vue({
            el: '#app1',
            data: {
                msg1: 'atguigu'
            },
            //定义局部指令，只在当前vm管理的范围内有效
            directives: {
                'lower-text': function (el, binding) {
                    el.textContent = binding.value.toLowerCase();
                }
            }
        })
        new Vue({
            el: '#app2',
            data: {
                msg2: 'kjkjkjkjk'
            },
        })
    </script>
</body>

</html>